﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using ENail.Domain.Core;
using ENail.Domain.Core.Contract.Services;
using ENail.Portal.Web.Models;

namespace ENail.Portal.Web.Controllers
{
    public class VendorController: DUALController<VendorListViewItem,
                                                       VendorViewModel,
                                                       Vendor>
    {
        private readonly IVendorService _Vendor;
        private readonly ITaskService _taskService;
        private TaskManager _taskManager;

        public VendorController(IVendorService Vendor, ITaskService taskService)
            : base("VendorList", 
                   "Vendor", 
                   new VendorListViewModelMapper(),
                   new VendorViewModelMapper())
        {
            _Vendor = Vendor;
            _taskService = taskService;
            _taskManager = new TaskManager(_taskService);

        }

        protected override List<Vendor> GetList()
        {
            return _Vendor.GetAllActiveVendors().ToList();
        }

        protected override Vendor Get(int id)
        {
            return _Vendor.GetVendor(id);
        }

        protected override void Add(Vendor domainModel)
        {
            User user = User as User;
            domainModel.NailSalon = user.NailSalon;

            _Vendor.InsertVendor(domainModel);
        }

        protected override void Update(Vendor domainModel)
        {
            _Vendor.UpdateVendor(domainModel);
        }

        protected override void Delete(Vendor domainModel)
        {
            _Vendor.InActiveVendor(domainModel);
        }
        #region View Task
        [ActionName("InitializeTask")]
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post | HttpVerbs.Head)]

        public ActionResult InitializeTask()
        {
            return PartialView("_Task", _taskManager.GetTaskModel());
        }
        #endregion

    }
}